package gameEngine;

public class Piece extends PlayerSon {

	private int size;
	private int[][] configuration;


	public Piece(int[][] _configuration, Player _parent){
		super(_parent);
		this.configuration = _configuration;
		setSize();
	}
	
	/**
	 * @return the configuration
	 */
	public int[][] getConfiguration() {
		return configuration;
	}

	/**
	 * @param configuration the configuration to set
	 */
	public void setConfiguration(int[][] configuration) {
		this.configuration = configuration;
		setSize();
		setChanged();
		notifyObservers();
	}
	// ping ?
	// non rien en fait
	/**
	 * @param size the size to set
	 */
	public void setSize() {
		setSize(getCaseCount());
		setChanged();
		notifyObservers();
	}
	
	private void setSize(int size) {
		this.size = size;
		setChanged();
		notifyObservers();
	}

	/**
	 * @return the size
	 */
	public int getSize() {
		return size;
	}
	
	public int getLineCount() {
		return this.configuration.length;
	}
	


	/*
	 * @return the number of cases of the piece
	 */
	public int getCaseCount() {
		int res = 0;
		for(int i = 0; i < configuration.length; i++) {
			res += configuration[i].length;
		}
		return res;
		
	}
	
	public int[][] render() {
		int [][] res = 
			{
				{ 0, 0, 0, 0, 0},
				{ 0, 0, 0, 0, 0},
				{ 0, 0, 0, 0, 0},
				{ 0, 0, 0, 0, 0},
				{ 0, 0, 0, 0, 0},
			};
		for(int i = 0; i < configuration.length; i++) {
			for(int j = 0; j < configuration[i].length; j++) {
				System.out.println("i : " + i + ", j : " +j + ", p : " + configuration[i][j]);
				res[i][configuration[i][j]] = 1;
			}
		}
		return res;
	}

}
